<?php
namespace App\DBs;

use Illuminate\Support\Facades\DB;

class BaseDB
{
    /**
     * 基本DB
     */

    public function __construct()
    {
    }

    /**
     * 生成随机字符串，数字字母字符混合
     */
    public static function getRandStr($length=6)
    {
        //数字、字母组合
        $str = '';
        $chars = 'ABCDEFGHJKLMNPQRSTUVWXYZ23456789abcdefghjkmnpqrstuvwxyz!:=-_!$%^&*';
        $max = strlen($chars) - 1;
        for($i = 0; $i < $length; $i++) {
            $str .= $chars[mt_rand(0, $max)];
        }
        return $str;
    }

    /**
     * 通过UID，获取Uname
     */
    public function getAdminName($adminId)
    {
        $table = 'admin';
        $model = DB::table($table)->where('id',$adminId)->first();
        return $model ? $model->name : '未定义';
    }

    /**
     * 判断图片
     */
    public function isImg($adminId,$genre,$fromid)
    {
        $db = new ImgDB();
        return $db->isImg($adminId,$genre,$fromid);
    }

    /**
     * 获取图片
     */
    public function getImgs($adminId,$genre,$fromid)
    {
        $db = new ImgDB();
        return $db->isImg($adminId,$genre,$fromid);
    }
}